package com.yakami.ocean.view.activity;

import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.yakami.ocean.R;
import com.yakami.ocean.adapter.PagerAdapter;
import com.yakami.ocean.view.activity.base.BaseHoldBackTransparentTabActivity;
import com.yakami.ocean.view.fragment.LoginFragment;
import com.yakami.ocean.view.fragment.SignUpFragment;

import butterknife.Bind;

/**
 * @author Yakami, Created on 2016/4/26
 */
public class LoginActivity extends BaseHoldBackTransparentTabActivity {

    @Bind(R.id.tab_layout) TabLayout mTabLayout;
    @Bind(R.id.view_pager) ViewPager mViewPager;
    @Bind(R.id.login_banner) ImageView mBanner;

    private PagerAdapter mPagerAdapter;

    @Override
    public void onCreate(Bundle savedInstanceBundle) {
        super.onCreate(savedInstanceBundle);
        mTitle.setText(mRes.getString(R.string.user_login));

//        //设置status bar背景view的高度, 设置status bar为全透明
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            ViewGroup.LayoutParams params = mBanner.getLayoutParams();
            params.height = getStatusBarHeight() + params.height;
            mBanner.setLayoutParams(params);
        }
//
        initTabs(savedInstanceBundle != null);
    }

    @Override
    protected int onBindLayout() {
        return R.layout.activity_login;
    }

    @Override
    protected void initTabs(boolean isRestarted) {
        super.initTabs(isRestarted);

        mPagerAdapter = new PagerAdapter(getSupportFragmentManager());

        if (mPagerAdapter.fragmentList.size() == 0) {
            LoginFragment loginFragment = new LoginFragment();
            SignUpFragment signUpFragment = new SignUpFragment();

            mPagerAdapter.addFragment(loginFragment, mRes.getString(R.string.login));
            mPagerAdapter.addFragment(signUpFragment, mRes.getString(R.string.sign_up));

            mViewPager.setOffscreenPageLimit(2);
            mPagerAdapter.notifyDataSetChanged();
            mViewPager.setAdapter(mPagerAdapter);
            mTabLayout.setupWithViewPager(mViewPager);
            mPagerAdapter.notifyDataSetChanged();
        }
    }
}
